/*
wellbye：这个文件是自动生成的，不要手工修改！ 
*/
using System;
using ILRuntime.CLR.Method;
using ILRuntime.Other;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Intepreter;

[ILRAdaptor]
public class ILRAdaptor_IAsyncStateMachine : CrossBindingAdaptor
{
    public override Type BaseCLRType { get { return typeof(System.Runtime.CompilerServices.IAsyncStateMachine); } }
    public override Type AdaptorType { get { return typeof(Adaptor); } }

    public override object CreateCLRInstance(ILRuntime.Runtime.Enviorment.AppDomain appDomain, ILTypeInstance instance)
    {
        return new Adaptor(appDomain, instance); //创建一个新的实例
    }

    //实际的适配器类需要继承你想继承的那个类，并且实现CrossBindingAdaptorType接口
    public class Adaptor : System.Runtime.CompilerServices.IAsyncStateMachine, CrossBindingAdaptorType
    {
        ILTypeInstance instance;
        ILRuntime.Runtime.Enviorment.AppDomain appDomain;

        public Adaptor() { }

        public Adaptor(ILRuntime.Runtime.Enviorment.AppDomain appDomain, ILTypeInstance instance)
        {
            this.appDomain = appDomain;
            this.instance = instance;
        }

        public ILTypeInstance ILInstance { get { return instance; } }

        
        
        IMethod methodMoveNext0;
        bool isCallingMoveNext0= false;
        
            public  void MoveNext() 
            { 
                if (methodMoveNext0 == null && instance!=null )
                {
                    methodMoveNext0 = instance.Type.GetMethod("MoveNext", 0);
                }
                if (methodMoveNext0 != null && !isCallingMoveNext0)
                {
                    isCallingMoveNext0 = true;

                    try{
                        
                        //无参数调用
                        object ret = appDomain.Invoke(methodMoveNext0, instance, null );
                        
                        
                        
                        isCallingMoveNext0 = false;

                        
                    }
                    catch(Exception e){
                        mb.App.logger.Log("**** Catch Exception In MoveNext *****");
                        mb.App.logger.Log(e.ToString());
                        mb.App.logger.Log("**********************");
                        throw e;
                    }
                }
                else
                {
                    
                    
                        
                        
                    

                }
            }
        
        
        
        IMethod methodSetStateMachine1;
        bool isCallingSetStateMachine1= false;
        
            public  void SetStateMachine(System.Runtime.CompilerServices.IAsyncStateMachine p0) 
            { 
                if (methodSetStateMachine1 == null && instance!=null )
                {
                    methodSetStateMachine1 = instance.Type.GetMethod("SetStateMachine", 1);
                }
                if (methodSetStateMachine1 != null && !isCallingSetStateMachine1)
                {
                    isCallingSetStateMachine1 = true;

                    try{
                        
                        //有参数，打包成数组
                        object[] param=new object[]{
                                p0,
                        };
                        object ret = appDomain.Invoke(methodSetStateMachine1, instance, param );
                        
                        
                        isCallingSetStateMachine1 = false;

                        
                    }
                    catch(Exception e){
                        mb.App.logger.Log("**** Catch Exception In SetStateMachine *****");
                        mb.App.logger.Log(e.ToString());
                        mb.App.logger.Log("**********************");
                        throw e;
                    }
                }
                else
                {
                    
                    
                        
                        
                    

                }
            }
        
        
    }
}